home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10477 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.5 KB

  1. Path: news.mindspring.com!usenet
  2. From: wdnick@mindspring.com (William "Doug" Nicholson)
  3. Newsgroups: comp.lang.c++
  4. Subject: Newbie question about function calling.
  5. Date: Fri, 08 Mar 1996 08:45:49 GMT
  6. Organization: MindSpring Enterprises
  7. Message-ID: <4hohd3$r9@brickbat.mindspring.com>
  8. Reply-To: wdnick@mindspring.com
  9. NNTP-Posting-Host: wdnick.mindspring.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. I'm having a problem somewhere between the following two functions.
  13. My main calls the function 'counter' (shown below) which in turn calls
  14. 'getinfo' by trying to assign 'getinfo's return value to the string
  15. variable 'filename'.  'Getinfo' prompts the user to enter a filename
  16. and stores it in the string 'infile'.  I've added a couple of lines
  17. below and started them in my post with the > so they will stand out.
  18. In the first one (in the getinfo function), the printf line prints
  19. whatever I type in at the prompt.  Theoretically this should be passed
  20. to 'filename' in the other function.  Well, the printf that tries to
  21. print "FILE = 'filename'" stops after "FILE =" and the computer locks
  22. up.
  23.  
  24. Anybody got any idea what's happening here?  Have I overlooked a
  25. really stupid thing or what?
  26.  
  27. Thanks for any help.  The problem area is listed below.
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35. char getinfo(void)
  36. /*****************************************************************
  37.  * This function prompts the user for a filename and returns it. *
  38.  *****************************************************************/
  39. {
  40.     char    infile[15];    /* file to process        */
  41.  
  42.     printf("Enter the path and filename of a file to process ");
  43.     printf("or enter XX to quit >");
  44.     scanf("%s", infile);
  45.  
  46. >    printf("FILE = %s\n\n", infile);
  47.  
  48.     return(infile[15]);
  49. }                /* end function getinfo        */
  50.  
  51. int counter(void)
  52. /*****************************************************************
  53.  * This function counts the number of times that each character  *
  54.  * is used in a file and returns the count.                      *
  55.  *****************************************************************/
  56. {
  57.     int    i,        /* lengths of triangle sides    */
  58.         count[128];    /* character count array    */
  59.  
  60.     char    chr,
  61.         filename[15] = "",
  62.         foo[2] = "1";
  63.  
  64.     FILE    *inp,        /* input file pointer        */
  65.         *outp;        /* output file pointer        */
  66.  
  67.     filename[15] = getinfo();
  68.  
  69. >    printf("FILE = %s\n\n", filename);
  70.  
  71.  
  72.  
  73. William D. Nicholson                                       wdnick@mindspring.com 
  74. Mechanical Engineering Student       
  75. Southern College of Technology                           It is what you make it.
  76. Under heavy construction:  http://www.mindspring.com/~wdnick/home.html
  77.  
  78.